package com.neulogistics.contrib.procuredcenter.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.contrib.procuredcenter.api.application.viewmodel.GoodsViewModel;
import com.neulogistics.contrib.procuredcenter.domain.model.valueobject.Address;
import com.neulogistics.contrib.procuredcenter.domain.model.valueobject.VendorInfo;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.GoodsPO;
import org.springframework.beans.BeanUtils;

public class GoodsPOVMConverter {
    private static final int Rate = 100;

    public static GoodsViewModel POToVM(GoodsPO goodsPO){
        if (goodsPO == null)
            return null;

        GoodsViewModel goodsViewModel = new GoodsViewModel();
        BeanUtils.copyProperties(goodsPO, goodsViewModel);
        // json对象转换
        goodsViewModel.setVendorInfo(JSONUtil.toBean(goodsPO.getVendorInfo(), VendorInfo.class));
        // 价格转换
        goodsViewModel.setGoodsPrice(Double.valueOf(goodsPO.getGoodsPrice()) / Rate);
        goodsViewModel.setGoodsCost(Double.valueOf(goodsPO.getGoodsCost()) / Rate);

        return goodsViewModel;
    }
}
